<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <style>
        body {
            width: 320px;
            padding: 16px;
            font-family: 'Microsoft YaHei', sans-serif;
            margin: 0;
        }
        
        .container {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }
        
        .header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 16px;
        }
        
        .logo {
            width: 32px;
            height: 32px;
        }
        
        .title {
            font-size: 18px;
            font-weight: bold;
            color: #333;
        }
        
        .action-buttons {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 8px;
        }
        
        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            background: #4CAF50;
            color: white;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .btn:hover {
            background: #45a049;
            opacity: 0.9;
        }
        
        .btn.secondary {
            background: #2196F3;
        }
        
        .btn.secondary:hover {
            background: #1976D2;
        }
        
        .settings {
            margin-top: 16px;
            padding-top: 16px;
            border-top: 1px solid #eee;
        }
        
        .settings-title {
            font-size: 14px;
            color: #666;
            margin-bottom: 8px;
        }
        
        .settings-options {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }
        
        .switch {
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .switch-label {
            font-size: 14px;
            color: #333;
        }
        
        .input-group {
            display: flex;
            flex-direction: column;
            gap: 4px;
        }
        
        .input-label {
            font-size: 12px;
            color: #666;
        }
        
        .input-field {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
            transition: border-color 0.3s ease;
        }
        
        .input-field:focus {
            outline: none;
            border-color: #4CAF50;
        }
        
        .input-field.password {
            font-family: monospace;
        }
        
        .loading {
            display: none;
            text-align: center;
            margin-top: 8px;
        }
        
        .loading.active {
            display: block;
        }
        
        .progress-bar {
            width: 100%;
            height: 4px;
            background: #eee;
            border-radius: 2px;
            overflow: hidden;
        }
        
        .progress-bar-fill {
            height: 100%;
            background: #4CAF50;
            width: 0%;
            transition: width 0.3s ease;
        }
        
        .save-btn {
            margin-top: 8px;
            background: #4CAF50;
            color: white;
            border: none;
            padding: 8px;
            border-radius: 4px;
            cursor: pointer;
            transition: background 0.3s ease;
        }
        
        .save-btn:hover {
            background: #45a049;
        }
        
        .save-btn:disabled {
            background: #ccc;
            cursor: not-allowed;
        }
        
        .url-patterns {
            margin-top: 20px;
            border-top: 1px solid #eee;
            padding-top: 20px;
        }
        
        .url-patterns-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .url-patterns-title {
            font-size: 16px;
            font-weight: 500;
            color: #333;
        }
        
        #addUrlPattern {
            background: #4CAF50;
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 6px;
            transition: all 0.3s ease;
        }
        
        #addUrlPattern:hover {
            background: #45a049;
            transform: translateY(-1px);
        }
        
        #addUrlPattern:active {
            transform: translateY(0);
        }
        
        #urlPatternsList {
            display: flex;
            flex-direction: column;
            gap: 8px;
            max-height: 200px;
            overflow-y: auto;
            padding-right: 5px;
        }
        
        #urlPatternsList::-webkit-scrollbar {
            width: 6px;
        }
        
        #urlPatternsList::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 3px;
        }
        
        #urlPatternsList::-webkit-scrollbar-thumb {
            background: #888;
            border-radius: 3px;
        }
        
        #urlPatternsList::-webkit-scrollbar-thumb:hover {
            background: #555;
        }
        
        .url-pattern-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 15px;
            background: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.2s ease;
        }
        
        .url-pattern-item:hover {
            background: #f1f3f5;
            border-color: #dee2e6;
            transform: translateX(2px);
        }
        
        .url-pattern-item span {
            font-size: 14px;
            color: #495057;
            flex: 1;
        }
        
        .url-pattern-item .delete-btn {
            background: none;
            border: none;
            color: #dc3545;
            padding: 4px 8px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 12px;
            opacity: 0;
            transition: all 0.2s ease;
        }
        
        .url-pattern-item:hover .delete-btn {
            opacity: 1;
        }
        
        .url-pattern-item .delete-btn:hover {
            background: #ffebee;
        }
        
        .url-pattern-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.6);
            z-index: 1000;
            align-items: center;
            justify-content: center;
            backdrop-filter: blur(4px);
        }
        
        .url-pattern-modal.active {
            display: flex;
            animation: modalFadeIn 0.3s ease;
        }
        
        @keyframes modalFadeIn {
            from {
                opacity: 0;
                transform: scale(0.95);
            }
            to {
                opacity: 1;
                transform: scale(1);
            }
        }
        
        .url-pattern-modal-content {
            background: white;
            padding: 24px;
            border-radius: 12px;
            width: 90%;
            max-width: 500px;
            max-height: 90vh;
            overflow-y: auto;
            position: relative;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        
        .url-pattern-modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 24px;
            padding-bottom: 16px;
            border-bottom: 1px solid #eee;
        }
        
        .url-pattern-modal-title {
            font-size: 20px;
            font-weight: 600;
            color: #333;
            margin: 0;
        }
        
        .url-pattern-modal-close {
            background: none;
            border: none;
            font-size: 24px;
            color: #666;
            cursor: pointer;
            padding: 4px 8px;
            line-height: 1;
            transition: color 0.2s;
            border-radius: 50%;
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .url-pattern-modal-close:hover {
            color: #333;
            background: #f5f5f5;
        }
        
        .url-pattern-form {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }
        
        .form-group {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }
        
        .form-label {
            font-size: 14px;
            color: #555;
            font-weight: 500;
        }
        
        .form-input {
            padding: 10px 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 14px;
            transition: all 0.3s;
            background: #f8f9fa;
        }
        
        .form-input:focus {
            outline: none;
            border-color: #4CAF50;
            background: white;
            box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.1);
        }
        
        .form-select {
            padding: 10px 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 14px;
            background: #f8f9fa;
            cursor: pointer;
            transition: all 0.3s;
            appearance: none;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8.825L1.175 4 2.238 2.938 6 6.7l3.763-3.763L10.825 4z'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 12px center;
            padding-right: 32px;
        }
        
        .form-select:focus {
            outline: none;
            border-color: #4CAF50;
            background-color: white;
            box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.1);
        }
        
        .custom-text-area {
            display: none;
            margin-top: 8px;
        }
        
        .custom-text-area.active {
            display: block;
            animation: slideDown 0.3s ease;
        }
        
        @keyframes slideDown {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .custom-text-input {
            width: 100%;
            min-height: 120px;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 14px;
            resize: vertical;
            transition: all 0.3s;
            background: #f8f9fa;
        }
        
        .custom-text-input:focus {
            outline: none;
            border-color: #4CAF50;
            background: white;
            box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.1);
        }
        
        .modal-actions {
            display: flex;
            justify-content: flex-end;
            gap: 12px;
            margin-top: 24px;
            padding-top: 20px;
            border-top: 1px solid #eee;
        }
        
        .modal-btn {
            padding: 10px 20px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.3s;
        }
        
        .modal-btn.cancel {
            background: #f5f5f5;
            color: #666;
        }
        
        .modal-btn.cancel:hover {
            background: #e0e0e0;
            color: #333;
        }
        
        .modal-btn.save {
            background: #4CAF50;
            color: white;
        }
        
        .modal-btn.save:hover {
            background: #45a049;
            transform: translateY(-1px);
        }
        
        .modal-btn.save:active {
            transform: translateY(0);
        }
        
        .form-text {
            font-size: 12px;
            color: #666;
            margin-top: 4px;
        }
        
        .error-message {
            color: #f44336;
            font-size: 12px;
            margin-top: 4px;
        }
        
        .success-message {
            position: fixed;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: #4CAF50;
            color: white;
            padding: 10px 20px;
            border-radius: 4px;
            z-index: 1000;
        }
        
        /* URL模式列表样式 */
        .url-patterns-container {
            max-height: 300px;
            overflow-y: auto;
            margin: 10px 0;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        
        .url-pattern-row {
            display: flex;
            align-items: center;
            padding: 8px;
            border-bottom: 1px solid #eee;
            position: relative;
            cursor: pointer;
        }
        
        .url-pattern-row:hover {
            background-color: #f5f5f5;
        }
        
        .url-pattern-row .pattern-name-container {
            flex: 1;
            padding: 4px 8px;
            border-radius: 4px;
            background: #f0f0f0;
            margin-right: 8px;
            cursor: pointer;
            transition: background-color 0.2s;
        }
        
        .url-pattern-row:hover .pattern-name-container {
            background: #e0e0e0;
        }
        
        .url-pattern-row .delete-btn {
            width: 24px;
            height: 24px;
            padding: 0;
            border: none;
            background: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #ff4444;
            transition: color 0.2s;
            opacity: 0;
        }
        
        .url-pattern-row:hover .delete-btn {
            opacity: 1;
        }
        
        .url-pattern-row .delete-btn:hover {
            color: #cc0000;
        }
        
        .url-pattern-row .delete-btn::before {
            content: "×";
            font-size: 20px;
            font-weight: bold;
        }
        
        .url-pattern-row .edit-btn {
            width: 24px;
            height: 24px;
            padding: 0;
            border: none;
            background: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #2196F3;
            transition: color 0.2s;
            margin-right: 4px;
            opacity: 0;
        }
        
        .url-pattern-row:hover .edit-btn {
            opacity: 1;
        }
        
        .url-pattern-row .edit-btn:hover {
            color: #1976D2;
        }
        
        .url-pattern-row .edit-btn::before {
            content: "✎";
            font-size: 16px;
        }
        
        .shortcut-input {
            padding: 6px 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 12px;
            width: 120px;
            cursor: pointer;
            background-color: #f8f9fa;
            transition: all 0.2s;
        }
        
        .shortcut-input:hover {
            background-color: #e9ecef;
        }
        
        .shortcut-input.recording {
            background-color: #ffebee;
            border-color: #f44336;
            box-shadow: 0 0 0 2px rgba(244, 67, 54, 0.25);
            animation: pulse 1.5s infinite;
        }
        
        @keyframes pulse {
            0% {
                box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.4);
            }
            70% {
                box-shadow: 0 0 0 6px rgba(244, 67, 54, 0);
            }
            100% {
                box-shadow: 0 0 0 0 rgba(244, 67, 54, 0);
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <img src="icons/icon48.png" class="logo" alt="Logo">
            <span class="title">智能助手</span>
        </div>
        
        <div class="action-buttons">
            <button class="btn" id="translatePage">翻译页面</button>
            <button class="btn secondary" id="summarizePage">总结页面</button>
            <button class="btn" id="translateAndSummarize">翻译并总结</button>
            <button class="btn secondary" id="importData">导入</button>
            <button class="btn secondary" id="exportData">导出</button>
        </div>
        
        <div class="settings">
            <div class="settings-title">设置</div>
            <div class="settings-options">
                <div class="input-group">
                    <label class="input-label">API密钥</label>
                    <input type="password" class="input-field password" id="apiKey" placeholder="输入您的API密钥">
                </div>
                
                <div class="input-group">
                    <label class="input-label">基础URL</label>
                    <input type="text" class="input-field" id="baseUrl" placeholder="https://platform.moonshot.cn/v1">
                </div>
                
                <div class="input-group">
                    <label class="input-label">模型名称</label>
                    <input type="text" id="modelName" class="input-field" placeholder="moonshot-v1-8k">
                </div>
                
                <div class="switch">
                    <span class="switch-label">自动翻译</span>
                    <input type="checkbox" id="autoTranslate">
                </div>
                
                <div class="switch">
                    <span class="switch-label">保存历史记录</span>
                    <input type="checkbox" id="saveHistory">
                </div>
                
                <div class="url-patterns">
                    <div class="settings-title">URL模式配置</div>
                    <div id="urlPatterns" class="url-patterns-container">
                        <!-- URL模式配置将在这里动态添加 -->
                    </div>
                    <button id="addUrlPattern" class="add-pattern-btn">添加URL模式</button>
                </div>
                
                <!-- URL模式编辑模态框 -->
                <div id="urlPatternModal" class="url-pattern-modal">
                    <div class="url-pattern-modal-content">
                        <div class="url-pattern-modal-header">
                            <div class="url-pattern-modal-title">编辑配置</div>
                            <button class="url-pattern-modal-close">&times;</button>
                        </div>
                        <form class="url-pattern-form">
                            <div class="form-group">
                                <label class="form-label">按钮名称</label>
                                <input type="text" class="form-input" id="buttonName" required>
                            </div>
                            <div class="form-group">
                                <label for="pattern">URL模式:</label>
                                <input type="text" id="pattern" class="form-control" placeholder="例如: example.com">
                            </div>
                            <div class="form-group">
                                <label for="backend">后端地址:</label>
                                <input type="text" id="backend" class="form-control" placeholder="例如: http://localhost:8000">
                            </div>
                            <div class="form-group">
                                <label for="shortcut">快捷键:</label>
                                <div class="shortcut-input-container">
                                    <input type="text" id="shortcut" class="form-input shortcut-input" readonly placeholder="点击此处设置快捷键">
                                    <button type="button" class="shortcut-clear" title="清除快捷键">&times;</button>
                                </div>
                                <small class="form-text text-muted">点击输入框，然后按下快捷键组合</small>
                            </div>
                            <div class="form-group">
                                <label class="form-label">发送内容</label>
                                <select class="form-select" id="contentType">
                                    <option value="custom">自定义文本</option>
                                    <option value="pageContent">页面内容</option>
                                    <option value="cookies">Cookie信息</option>
                                </select>
                            </div>
                            <div class="custom-text-area">
                                <textarea class="custom-text-input" id="customText" placeholder="输入要发送的自定义文本"></textarea>
                            </div>
                            <div class="modal-actions">
                                <button type="button" class="modal-btn cancel">取消</button>
                                <button type="submit" class="modal-btn save">保存</button>
                            </div>
                        </form>
                    </div>
                </div>
                
                <button class="save-btn" id="saveSettings">保存设置</button>
            </div>
        </div>
        
        <div class="loading" id="loading">
            <div class="progress-bar">
                <div class="progress-bar-fill"></div>
            </div>
            <span>处理中...</span>
        </div>
    </div>
    <script src="popup.js"></script>
</body>
</html> 